package main

import (
	"io"
	"net/http"
	"fmt"
	"log"
)

func main() {

	mumu_test()

}


func mumu_test() {
	fmt.Println("mumu_test")
	m := make(map[string]HandlerFunc)
	m["/22"] = demo
	r :=  &Router{
		m,
	}
	fmt.Printf("%+v\n", *r)
	mumu := &Mumu{r}
	server := &http.Server{
		Handler: mumu,
		Addr:    ":8099",
	}
	err := server.ListenAndServe()
	if err != nil {
		log.Fatal(err.Error())
	}
}

type HandlerFunc func(ctx *Context)

type Mumu struct {
	// mu     sync.RWMutex
	router *Router
}

func (m *Mumu) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	ctx := &Context{
		w,
		r,
	}
	m.router.m["/22"](ctx)
}

type Router struct {
	m map[string]HandlerFunc
}

type Context struct {
	w   http.ResponseWriter
	req *http.Request
}

func (ctx *Context) WriteString(str string) {
	io.WriteString(ctx.w, str)
}

func demo(ctx *Context) {
	ctx.WriteString("你好哦")
}

